<%--
  Created by IntelliJ IDEA.
  User: 郑自航
  Date: 2018/7/9
  Time: 14:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="basePath" value="${r'${pageContext.request.contextPath}'}"></c:set>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${entity}</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="stylesheet" href="${r'${basePath}'}/layui/css/layui.css">
    <script type="text/javascript" src="${r'${basePath}'}/js/plugin/jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="${r'${basePath}'}/js/plugin/jquery.i18n.properties.min.js"></script>
    <script src="${r'${basePath}'}/layui/layui.js"></script>
</head>

<body class="page-body">
<!--contentBegin-->
<div class="layui-fluid">
			<span class="layui-breadcrumb" lay-separator=">">
			  <a href="" class="l-lab-text">Home</a>
			  <a href="" class="l-lab-text"><#if package.ModuleName??>${package.ModuleName}</#if></a>
			  <a href="" class="l-lab-text">${entity}</a>
			</span>
</div>
<div class="layui-inline"></div>
<div id="content">
    <form class="layui-form" action="" lay-filter="example">
        <input name="id" type="hidden" value="${r'${id}'}" id="${table.entityPath}_id">
    <#-- ----------  BEGIN 字段循环遍历  ---------->
    <#list table.fields as field>
    <#--${field.propertyName}-->
        <#if field.keyFlag>
            <#assign keyPropertyName="${field.propertyName}"/>
        </#if>
        <#if field.propertyName != "id" && field.propertyName != "deleteFlag" >

            <#if field.propertyType == "String">
                <#if !field.propertyName?contains("update") && !field.propertyName?contains("create") >
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label l-lab-text"><#if field.comment!?length gt 0>${field.comment}<#else>${field.capitalName}</#if>:</label>
                        <div class="layui-input-inline">
                            <input name="${field.propertyName}" id="${field.propertyName}_inputId" lay-verify="" placeholder="${field.comment}" autocomplete="true" class="layui-input"
                                   type="text">
                        </div>
                    </div>
                </div>
                </#if>
            <#elseif field.propertyType == "Double">
            <div class="layui-form-item">
                 <div class="layui-inline">
                     <label class="layui-form-label l-lab-text"><#if field.comment!?length gt 0>${field.comment}<#else>${field.capitalName}</#if>:</label>
                     <div class="layui-input-inline">
                         <input name="${field.propertyName}" id="${field.propertyName}_inputId" lay-verify="" placeholder="${field.comment}" autocomplete="true" class="layui-input"
                                type="number">
                     </div>
                 </div>
             </div>
            <#elseif field.propertyType == "BigDecimal">
            <div class="layui-form-item">
                 <div class="layui-inline">
                     <label class="layui-form-label l-lab-text"><#if field.comment!?length gt 0>${field.comment}<#else>${field.capitalName}</#if>:</label>
                     <div class="layui-input-inline">
                         <input name="${field.propertyName}" id="${field.propertyName}_inputId" lay-verify="" placeholder="${field.comment}" autocomplete="true" class="layui-input"
                                type="number">
                     </div>
                 </div>
             </div>
            <#elseif field.propertyType == "Integer">
                <#if !field.propertyName?contains("Id") >
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label l-lab-text"><#if field.comment!?length gt 0>${field.comment}<#else>${field.capitalName}</#if>:</label>
                        <div class="layui-input-inline">
                            <select name="${field.propertyName}" id="${field.propertyName}_selectId" lay-search="">
                                <option value="" class="l-lab-text">All</option>
                            </select>
                        </div>
                    </div>
                </div>
                </#if>
            <#elseif field.propertyType == "Date">
            <#-- -----   字符串字段,普通文本输入框   ----->
            <#else>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label l-lab-text"><#if field.comment!?length gt 0>${field.comment}<#else>${field.capitalName}</#if>:</label>
                    <div class="layui-input-inline">
                        <input name="${field.propertyName}" id="${field.propertyName}_inputId" lay-verify="" placeholder="${field.comment}" autocomplete="true" class="layui-input"
                               type="text">
                    </div>
                </div>
            </div>
            </#if>
        </#if>
    </#list>
    <#------------  END 字段循环遍历  ---------->

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn l-lab-text" lay-submit lay-filter="formDemo">OK</button>
                <button class="layui-btn layui-btn-warm l-lab-text" onclick="top.layer.close(top.add${entity}_layer)" >Cancel</button>
                <button type="reset" class="layui-btn layui-btn-primary l-lab-text">Rest</button>
            </div>
        </div>
    </form>
</div>
<div class="ibox-content">
    <table class="table-hide" id="demoTable" lay-data="{id: 'idApply'}" lay-filter="Apply"></table>
</div>
<script src="${r'${basePath}'}/js/i18n.js"></script>
<script src="${r'${basePath}'}/js/common.js"></script>
<script src="${r'${basePath}'}/js/DateFormate.js"></script>
<script>
    $(function () {
        doTranslate();
        /*初始化下拉选*/
        var types=[
        <#list table.fields as field>
            <#if field.propertyType == "Integer">
                <#if field.propertyName != "id" && field.propertyName != "deleteFlag" >
                    <#if !field.propertyName?contains("Id") >
                '${table.entityPath}_${field.propertyName}',
                    </#if>
                </#if>
            </#if>
        </#list>];
        //批量初始化下拉选
        initBatchSelect(types,function () {
            doSetEditFormData();
            initForm();
        });
    })
    function doSetEditFormData() {
        var id=$("#${table.entityPath}_id").val();
        if(id){
            $.post('<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/find${entity}One.do',{id:id},function (result) {
                if(result&&result.code==0){
                    var data=result.data;
                   // debugger
                    layui.use('form', function(){
                        var form = layui.form;
                        //表单初始赋值
                        form.val('example', {
<#list table.fields as field>
        <#if field.propertyName != "id" && field.propertyName != "deleteFlag" && field.propertyType != "Date">
                            "${field.propertyName}": data.${field.propertyName},
    </#if>
</#list>
                        })
                        form.render();
                    });
                }else {
                    top.myLayer.confirm(top._loadText(result.msg));
                }
            })

        }
    }
    function initForm(){
        layui.use(['form','element'], function(){
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function(data){
                // debugger
                // top.layer.msg(JSON.stringify(data.field));
                var id=data.field.id;
                var url=id?'<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/update${entity}.do':'<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/add${entity}.do'
                $.post(url,data.field,function (result) {
                    if(result&&result.code==0){
                        top.myLayer.msg(top._loadText('Add successful'),null,top.layer.close(top.add${entity}_layer));
                    }else{
                        top.myLayer.confirm(top._loadText('Add failed')+top._loadText(result.msg));
                    }
                })
                return false;
            });
        });
    }
</script>
</body>
</html>
